package ua.tach.shortl;

import ua.tach.shortl.logic.Country;

public class Bank extends RenderCounter {
	public static final int WAGON_COST = 1;
	public static final int TREE_COST = 1;
	public static final int RAIL_COST = 1;
	private int oldValue;

	public Bank(int px, int py, int size, int i) {
		digitPosX = px;
		digitPosY = py;
		digitSize = size;
		moveStep = 0;
		curValue = i;
		oldValue = i+1;
	}

	public void cutTree () {
		curValue -= TREE_COST;
	}

	public void getMoney (int m) {
		curValue -= m;
	}

	public void buildRail () {
		curValue -= RAIL_COST;
	}

	public void trainArrv (int wagons) {
		Country.cashSound.play();
		curValue += WAGON_COST*wagons;
	}

	public boolean btick () {
		if (moveStep <= 0) {
			if (curValue != oldValue) {
				oldValue += (curValue > oldValue)? 1 : -1;
				updateCnt(oldValue);
			}
		} else {
			moveStep -= 2;
			if (moveStep <= 0)
				for (int i = digitSize-1; i>=0; --i) {
					oldDigits[i] = newDigits[i];
				}
		}

		return curValue>0;
	}
}
